#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int minimumRightShifts(vector<int>& nums) {
    int n = nums.size();
    int i = 1;
    while (i < n && nums[i - 1] < nums[i])
        i++;
    if (i == n)
        return 0;

    if (nums[0] < nums[n - 1])
        return -1;

    int mid = i;
    i++;
    while (i < n && nums[i - 1] < nums[i])
        i++;
    if (i < n)
        return -1;
    return n - mid;
}

int minLengthAfterRemovals(vector<int>& nums) {
    int n = nums.size();
    int x = nums[n / 2];
    int max_cnt = upper_bound(nums.begin(), nums.end(), x) - lower_bound(nums.begin(), nums.end(), x);
    return max(max_cnt * 2 - n, n % 2); 
}

int main()
{
    vector<int> v = { 3,4,5,1,2 };
    minimumRightShifts(v);
	return 0;
}